package com.zlx.store.order.job;

import com.alibaba.druid.sql.visitor.functions.Now;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlx.store.domain.entity.Order;
import com.zlx.store.order.dao.OrderDao;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class CleanExpireOrder extends QuartzJobBean {
    @Autowired
    private OrderDao orderDao;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        int delete = orderDao.delete(
                new LambdaQueryWrapper<Order>().le(Order::getOrderCreateTime, LocalDateTime.now().minusYears(2))
        );
        log.debug("已经删除数量==》", delete);
    }
}
